<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<div id="app">
    <cpn @itemclicked="cpnClicked"></cpn>
</div>

<template id="cpn">
    <div>
        <button v-for="(item, index) in categories" @click="btnClick(item)">{{item.name}}</button>
    </div>
</template>

<script src="../../js/vue.js"></script>

<script>

    const cpn = {
        template: '#cpn',
        data(){
            return {
                categories: [
                    {id: 'aa', name: '热门推荐'},
                    {id: 'bb', name: '手机数码'},
                    {id: 'cc', name: '家用电器'},
                    {id: 'dd', name: '电脑办公'}
                ]
            }
        },
        methods: {
            btnClick(item){
                console.log(item);
                // 发射
                this.$emit('itemclicked', item)
            }
        }
    }

    const vue = new Vue({
        el: "#app",
        data: {
            message: "Hello vue,你好！"
        },
        components:{
            cpn
        },
        methods: {
            cpnClicked(item){
                console.log('cpnClicked...'+item)
            }
        }
    });
</script>
</body>
</html>